﻿using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls.Renderers.Windows
{
    public abstract class ContentElementRenderer<TControl, TRenderer> : IContentElementRenderer<TControl, TRenderer>
        where TControl : ContentElement<TControl, TRenderer>
        where TRenderer : class, IContentElementRenderer<TControl, TRenderer>
    {
        #region Methods

        public void RenderUiXmlBegin(TControl control, CodeWriter writer)
        {
            if (control != null)
            {
                OnRenderUiXmlBegin(control, writer);
            }
        }

        public void RenderUiXml(TControl control, CodeWriter writer)
        {
            if (control != null)
            {
                OnRenderUiXmlBegin(control, writer);
                OnRenderUiXmlContent(control, writer);
                OnRenderUiXmlEnd(control, writer);
            }
        }

        public void RenderUiXmlEnd(TControl control, CodeWriter writer)
        {
            if (control != null)
            {
                OnRenderUiXmlEnd(control, writer);
            }
        }

        protected virtual void OnRenderUiXmlContent(TControl control, CodeWriter writer)
        {
        }

        protected virtual void OnRenderUiXmlBegin(TControl control, CodeWriter writer)
        {
        }

        protected virtual void OnRenderUiXmlEnd(TControl control, CodeWriter writer)
        {
        }

        public void RenderUiCode(TControl control, CodeWriter writer)
        {
            OnRenderViewModelCs(control, writer);
        }

        protected virtual void OnRenderViewModelCs(TControl control, CodeWriter writer)
        {
        }

        #endregion Methods
    }
}